/**
 * 
 */
package com.bitBusy.manageyourriches.utilityClasses.adapters;

import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.bitBusy.manageyourriches.R;

/**
 * Custom adapter for spinner item - shows an image and text
 * @author SumaHarsha
 *
 */
public class SpinnerItemAdapter extends ArrayAdapter<String> implements SpinnerAdapters{
	
	/**Context*/
	private Context myContext; 
	
	/**Array of text keys*/
	private Object[] myKeyArray;
	
		
	/**Constructor
	 * @param context
	 * @param view to display
	 * @param map of text and images
	 */
	 public SpinnerItemAdapter(Context the_context, int the_displayViewID,
			    Map<String, Integer> the_items) {
			   super(the_context, the_displayViewID, the_items!=null?the_items.keySet().toArray(new String[the_items.size()]):null);
		 		myContext = the_context;
		 		if (the_items != null)
		        {
		 			myKeyArray =  the_items.keySet().toArray();
		        }
			  }

        @Override
        public View getDropDownView(int position, View convertView,ViewGroup parent) {
            return getCustomView(position, convertView, parent, Color.BLACK);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView(position, convertView, parent, Color.BLACK);
        }

        public View getCustomView(int position, View convertView, ViewGroup parent, int the_textColor) {

        	LayoutInflater inflater = (LayoutInflater) myContext
        			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         
        
            View item = inflater.inflate(R.layout.spinner_custom_look, parent, false);
            
            TextView desc =(TextView)item.findViewById(R.id.spinnerItemDesc);
            desc.setText(myKeyArray[position].toString());
            desc.setTextColor(the_textColor);
        //    ImageView icon=(ImageView)item.findViewById(R.id.spinnerItemImage);
         //   icon.setImageResource(myItems.get(myKeyArray[position]));
            return item;
            }

		/* (non-Javadoc)
		 * @see com.bitBusy.manageyourriches.utilityClasses.adapters.SpinnerAdapters#getItemPosition(java.lang.Object)
		 */
		@Override
		public int getItemPosition(Object the_item) {
			if (myKeyArray != null && the_item != null)
			{
				for (int i = 0; i< myKeyArray.length; i++)
				{
					if(myKeyArray[i].equals(the_item))
					{
						return i;
					}
				}
			}
			return -1;
		}
		

		
		

		
		
		

        }

			 

